<?php

namespace App\Http\Controllers\Admin;
use App\DTOS\Admin\ServerGroupDTO;
use App\Exceptions\ServiceException;
use App\Http\Controllers\Controller;
use App\Services\Game\HotVersionService;
use App\Services\Game\ServerGroupService;
use App\Utils\MyLog;
use App\Utils\ResponseUtil;
// 服务器分组列表
class HotVersionController extends Controller
{
    private HotVersionService $HotVersionService;
    private ServerGroupService $ServerGroupService;

    /**
     * ServerGroupController constructor.
     * @param HotVersionService $HotVersionService
     */
    public function __construct(HotVersionService $HotVersionService,ServerGroupService $ServerGroupService)
    {
        $this->HotVersionService = $HotVersionService;
        $this->ServerGroupService = $ServerGroupService;

    }


    public function newpaginate()
    {

        $paginate = $this->HotVersionService->newpaginate(new ServerGroupDTO(request()->all()));
        $res = [];
        $res['code'] = 0;
        $res['msg'] = 'success';
        $res['data'] = $paginate->items();
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }

    public function paginate()
    {
        $paginate = $this->HotVersionService->paginate(new ServerGroupDTO(request()->all()));
        $res = [];
        $res['code'] = 0;
        $res['msg'] = 'success';
        $res['data'] = $paginate->items();
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }

    public function add()
    {
        $data = request()->all();
        $this->HotVersionService->add($data);
        return ResponseUtil::success();
    }
    public function edit($id)
    {
        try {

            $data = request()->all();
            $this->HotVersionService->edit($id, $data);

            return ResponseUtil::success($data);
        } catch ( ServiceException $e ) {

            return ResponseUtil::error($e->getMessage());
        }
    }
    public function detail($id)
    {
        $data = $this->HotVersionService->detail($id);
        return ResponseUtil::success($data);
    }
    public function delete($id)
    {
        $this->HotVersionService->delete($id);
        return ResponseUtil::success();
    }



}
